import Tween = Laya.Tween;
import { RoleAction } from "../../../ADCore/Interfaces/IEnum";
import { StateMachine } from "../../../ADCore/Implements/ImpStateMachine/StateMachine";
import { RoleMoveParam } from "../../../ADCore/Implements/ImpRole/RoleMoveParam";

export default class RoleMoveState extends StateMachine {
  private _tween: Tween;
  private _moveParam: RoleMoveParam;
  onEnter(obj: RoleMoveParam = null): void {
    this.owner.disObjCtrl.aniController.playAniByState(RoleAction.move);
    this._moveParam = obj;
    if (!this._moveParam) {
      console.debug("ActorMoveState obj param is null");
      this.owner.changeState(RoleAction.idle);
    } else {
      this.tweenMove();
    }
  }
  private _step: number = 0;
  private tweenMove() {
    if (this._step < this._moveParam.path.length - 1) { 
    } else {
      //结束移动
      this.reset();
      this.owner.changeState(RoleAction.idle);
    }
  }
  private onMoveCmp(): void {
    this.owner.changeState(RoleAction.idle);
  }
  private reset(): void {
    this._step = 0;
    this._moveParam = null;
    if (this._tween) this._tween.clear();
    this._tween = null;
  }
  public onLeave(newState: RoleAction) {
    this.reset();
  }
}
